package com.esri.core.internal.tasks.ags;

import com.esri.core.internal.tasks.TaskListener;
import com.esri.core.io.UserCredentials;
import com.esri.core.portal.PortalItem;
import com.esri.core.portal.PortalQueryParams;
import com.esri.core.portal.PortalQueryResultSet;
import java.util.ArrayList;
import org.codehaus.jackson.JsonParser;
import org.codehaus.jackson.JsonToken;

/* loaded from: classes.dex */
public class aj extends com.esri.core.internal.tasks.d<PortalQueryResultSet<PortalItem>> {
    private static final long serialVersionUID = 1;

    public aj(al alVar, String str, UserCredentials userCredentials) {
        this(alVar, str, userCredentials, null);
    }

    public aj(al alVar, String str, UserCredentials userCredentials, TaskListener<PortalQueryResultSet<PortalItem>> taskListener) {
        super(alVar, a(str), userCredentials, taskListener);
    }

    private static final String a(String str) {
        return str + "/search";
    }

    @Override // com.esri.core.internal.tasks.a
    /* renamed from: a */
    public PortalQueryResultSet<PortalItem> execute() throws Exception {
        al alVar = (al) getActionInput();
        JsonParser a = com.esri.core.internal.io.handler.h.a(this.serviceURL, this.actionInput.generateRequestParams(), getServiceCredentials());
        if (com.esri.core.internal.util.d.c(a)) {
            ArrayList arrayList = new ArrayList();
            int i = 0;
            int i2 = 0;
            while (a.nextToken() != JsonToken.END_OBJECT) {
                String currentName = a.getCurrentName();
                a.nextToken();
                if (currentName.equals("query")) {
                    a.skipChildren();
                } else if (currentName.equals("total")) {
                    i2 = a.getIntValue();
                } else if (currentName.equals("start")) {
                    a.skipChildren();
                } else if (currentName.equals("num")) {
                    a.skipChildren();
                } else if (currentName.equals("nextStart")) {
                    i = a.getIntValue();
                } else if (currentName.equals("results")) {
                    while (a.nextToken() != JsonToken.END_ARRAY) {
                        arrayList.add(PortalItem.fromJson(a, ((al) getActionInput()).a));
                    }
                }
            }
            PortalQueryParams a2 = alVar.a();
            return new PortalQueryResultSet<>(a2, a2.withNextStart(i), i2, arrayList);
        }
        return null;
    }
}
